package org.pine.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.pine.api.enums.ResultCodeEnum;
import org.pine.common.exception.PineException;

import java.util.Arrays;
import java.util.Objects;

/**
 * 状态枚举
 *
 * @author pine
 * @version v1.0
 * @since 2025-04-19 14:29
 */
@AllArgsConstructor
@Getter
public enum StatusEnum implements DatabaseBaseEnum {

    INVALID(0, "无效"),
    VALID(1, "有效")

    ;

    @EnumValue
    private final Integer code;
    private final String desc;

    public static StatusEnum of(Integer code) {
        return Arrays.stream(StatusEnum.values()).filter(statusEnum -> Objects.equals(statusEnum.code, code))
                .findAny()
                .orElseThrow(() -> new PineException(ResultCodeEnum.DATA_NOT_FOUND_EXCEPTION.getCode(), "状态编码不存在"));
    }
}
